package com.heisen.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heisen.base.exception.RRException;
import com.heisen.base.utils.MyObjectUtils;
import com.heisen.database.service.impl.SuperServiceImpl;
import com.heisen.system.entity.Role;
import com.heisen.system.entity.RoleMenu;
import com.heisen.system.mapper.RoleMapper;
import com.heisen.system.mapper.RoleMenuMapper;
import com.heisen.system.query.RoleMenuQuery;
import com.heisen.system.query.RoleQuery;
import com.heisen.system.service.IRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heisen.system.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色菜单关联表 服务实现类
 * </p>
 *
 * @author sen
 * @since 2023-12-24
 */
@Service
public class RoleMenuServiceImpl  extends SuperServiceImpl<RoleMenuMapper, RoleMenu, RoleMenuQuery> implements IRoleMenuService {

    /**
     * 获取角色 绑定的菜单id
     * @param roleId
     * @return
     */
    @Override
    public List<Long> findSysRoleMenuIds(Long roleId) {
        List<RoleMenu> sysRoleMenus = selectAllRoleMenu(roleId);
        return sysRoleMenus.stream().map(RoleMenu::getMenuId).distinct().collect(Collectors.toList());
    }

    /**
     *  查出 角色菜单 和按钮
     * @param roleId
     * @return
     */
    @Override
    public List<RoleMenu> selectAllRoleMenu(Long roleId) {
        if(MyObjectUtils.isEmpty(roleId)) throw new RRException("roleId 为空");
        QueryWrapper<RoleMenu> wqSUM = new QueryWrapper<>();
        wqSUM.eq(RoleMenu.ROLE_ID,roleId);
        return this.baseMapper.selectList(wqSUM);
    }



}
